/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import com.jnetx.javax.sip.util.Parametrized;

import javax.sip.header.AuthenticationInfoHeader;
import javax.sip.header.Header;
import java.text.ParseException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class AuthenticationInfoHeaderImpl extends ParametrizedHeaderBase implements AuthenticationInfoHeader {
    private static final AuthenticationInfoHeaderParser parser = new AuthenticationInfoHeaderParser();

    protected HeaderParser getParser() {
        return parser;
    }

    public AuthenticationInfoHeaderImpl() {
        super(AuthenticationInfoHeader.NAME);
    }

    AuthenticationInfoHeaderImpl(byte[] data, int start, int end) {
        super(AuthenticationInfoHeader.NAME, data, start, end);
    }

    @Override
    protected Parametrized<Header> createParametrized() {
        return new Parametrized<Header>(this, Parametrized.QuotationType.DOUBLE);
    }

    protected String getValueAsString() {
        return "";
    }

    @Override
    protected StringBuilder getParametersAsString(StringBuilder sb, char delimiter) {
        return sb.append(parametrized.getParametersAsString(','));
    }

    public Object clone() {
        final AuthenticationInfoHeaderImpl header = new AuthenticationInfoHeaderImpl();
        header.cloneBase(this);
        if (parsed) {
            header.cloneParameters(this);
        }
        return header;
    }

    /**
     * {@inheritDoc}
     */
    public void setNextNonce(String nextNonce) throws ParseException {
        setParameter("nextnonce", nextNonce);
    }

    /**
     * {@inheritDoc}
     */
    public String getNextNonce() {
        return getParameter("nextnonce");
    }

    /**
     * {@inheritDoc}
     */
    public void setQop(String qop) throws ParseException {
        setParameter("qop", qop, Parametrized.QuotationType.NONE);
    }

    /**
     * {@inheritDoc}
     */
    public String getQop() {
        return getParameter("qop");
    }

    /**
     * {@inheritDoc}
     */
    public void setCNonce(String cNonce) throws ParseException {
        setParameter("cnonce", cNonce);
    }

    /**
     * {@inheritDoc}
     */
    public String getCNonce() {
        return getParameter("cnonce");
    }

    /**
     * {@inheritDoc}
     */
    public void setNonceCount(int nonceCount) throws ParseException {
        if (nonceCount == -1)
            removeParameter("nc");
        else
            setParameter("nc", Integer.toString(nonceCount), Parametrized.QuotationType.NONE);
    }

    /**
     * {@inheritDoc}
     */
    public int getNonceCount() {
        final String nc = getParameter("nc");
        if (nc == null)
            return -1;
        else
            return Integer.parseInt(nc);
    }

    /**
     * {@inheritDoc}
     */
    public void setResponse(String response) throws ParseException {
        setParameter("rspauth", response);
    }

    /**
     * {@inheritDoc}
     */
    public String getResponse() {
        return getParameter("rspauth");
    }
}
/*
 * $Log$
 */